home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Mac Pascal Primer, 4.0
/
Chap 3, Flying Line ƒ
/
Flying Line.p
next >
Wrap
Text File
|
1990-07-30
|
4KB
|
157 lines
program FlyingLine;
const
NUM_LINES = 50;
NIL_STRING = '';
NIL_TITLE = '';
VISIBLE = TRUE;
NO_GO_AWAY = FALSE;
NIL_REF_CON = 0;
type
IntPtr = ^INTEGER;
var
gLineWindow: WindowPtr;
gLines: array[1..NUM_LINES] of Rect;
gDeltaTop, gDeltaBottom: INTEGER;
gDeltaLeft, gDeltaRight: INTEGER;
gOldMBarHeight: INTEGER;
gMBarHeightPtr: IntPtr;
{--------------------------------> DrawLine <---}
procedure DrawLine (i: INTEGER);
begin
MoveTo(gLines[i].left, gLines[i].top);
LineTo(gLines[i].right, gLines[i].bottom);
end;
{--------------------------------> RecalcLine <---}
procedure RecalcLine (i: INTEGER);
begin
gLines[i].top := gLines[i].top + gDeltaTop;
if ((gLines[i].top < gLineWindow^.portRect.top) | (gLines[i].top > gLineWindow^.portRect.bottom)) then
gDeltaTop := gDeltaTop * (-1);
gLines[i].top := gLines[i].top + 2 * gDeltaTop;
gLines[i].bottom := gLines[i].bottom + gDeltaBottom;
if ((gLines[i].bottom < gLineWindow^.portRect.top) | (gLines[i].bottom > gLineWindow^.portRect.bottom)) then
gDeltaBottom := gDeltaBottom * (-1);
gLines[i].bottom := gLines[i].bottom + 2 * gDeltaBottom;
gLines[i].left := gLines[i].left + gDeltaLeft;
if ((gLines[i].left < gLineWindow^.portRect.left) | (gLines[i].left > gLineWindow^.portRect.right)) then
gDeltaLeft := gDeltaLeft * (-1);
gLines[i].left := gLines[i].left + 2 * gDeltaLeft;
gLines[i].right := gLines[i].right + gDeltaRight;
if ((gLines[i].right < gLineWindow^.portRect.left) | (gLines[i].right > gLineWindow^.portRect.right)) then
gDeltaRight := gDeltaRight * (-1);
gLines[i].right := gLines[i].right + 2 * gDeltaRight;
end;
{--------------------------------> MainLoop <---}
procedure MainLoop;
var
i: INTEGER;
begin
while (not Button) do
begin
DrawLine(NUM_LINES);
for i := NUM_LINES downto 2 do
gLines[i] := gLines[i - 1];
RecalcLine(1);
DrawLine(1);
gMBarHeightPtr^ := gOldMBarHeight;
end;
end;
{--------------------------------> Randomize <---}
function Randomize (range: INTEGER): INTEGER;
var
rawResult: LONGINT;
begin
rawResult := Random;
rawResult := abs(rawResult);
Randomize := (rawResult * range) div 32768;
end;
{--------------------------------> RandomRect <---}
procedure RandomRect (var myRect: Rect;
boundingWindow: WindowPtr);
begin
myRect.left := Randomize(boundingWindow^.portRect.right - boundingWindow^.portRect.left);
myRect.right := Randomize(boundingWindow^.portRect.right - boundingWindow^.portRect.left);
myRect.top := Randomize(boundingWindow^.portRect.bottom - boundingWindow^.portRect.top);
myRect.bottom := Randomize(boundingWindow^.portRect.bottom - boundingWindow^.portRect.top);
end;
{--------------------------------> LinesInit <---}
procedure LinesInit;
var
i: INTEGER;
begin
gDeltaTop := 3;
gDeltaBottom := 3;
gDeltaLeft := 2;
gDeltaRight := 6;
HideCursor;
GetDateTime(randSeed);
RandomRect(gLines[1], gLineWindow);
DrawLine(1);
for i := 2 to NUM_LINES do
begin
gLines[i] := gLines[i - 1];
RecalcLine(i);
DrawLine(i);
end;
end;
{--------------------------------> WindowInit <---}
procedure WindowInit;
var
totalRect, mBarRect: Rect;
mBarRgn: RgnHandle;
begin
gMBarHeightPtr := IntPtr($baa);
gOldMBarHeight := gMBarHeightPtr^;
gMBarHeightPtr^ := 0;
gLineWindow := NewWindow(nil, screenBits.bounds, NIL_TITLE, VISIBLE, plainDBox, WindowPtr(-1), NO_GO_AWAY, NIL_REF_CON);
SetRect(mBarRect, screenBits.bounds.left, screenBits.bounds.top, screenBits.bounds.right, screenBits.bounds.top + gOldMBarHeight);
mBarRgn := NewRgn;
RectRgn(mBarRgn, mBarRect);
UnionRgn(gLineWindow^.visRgn, mBarRgn, gLineWindow^.visRgn);
DisposeRgn(mBarRgn);
SetPort(gLineWindow);
FillRect(gLineWindow^.portRect, black); { Change black to ltGray, }
PenMode(patXor); { <--- and comment out this line }
end;
{--------------------------------> FlyingLine <---}
begin
WindowInit;
LinesInit;
MainLoop;
end.